from hames.ft import FunctionalTest
from wtforms import form, fields, validators

REQUIRED = validators.required()
OPTIONAL = validators.optional()

class AppTestFT(FunctionalTest):
    NAME = 'App Test'
    CATEGORY = 'Application Tests'
    DESCRIPTION = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' + \
                  'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco ' + \
                  'laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in ' + \
                  'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat ' + \
                  'non proident, sunt in culpa qui officia deserunt mollit anim id est laborumself.'

    class AccountForm(form.Form):
        """ Form for searching for assets. """
        email      = fields.TextField(label='Email', default='joe@example.com', validators=[REQUIRED])
        first_name = fields.TextField(label='First name', default='Joe', validators=[OPTIONAL])
        last_name  = fields.TextField(label='Last name', default='Smith', validators=[OPTIONAL])
        phone      = fields.TextField(label='Phone', default='1-306-555-1212', validators=[OPTIONAL])

        def validate_first_name(form, field):
            """ Called by the wtform framework; the name of the method is the key. """
            if (not field.data and form.last_name.data) or (field.data and not form.last_name.data):
                raise ValueError('Both first name and last name must be specified if either are.')

    FORM_CLASS = AccountForm

    def process(self, form):
        self.messages.append('something great')
        self.messages.append('is about to happen!')
        # raise Exception('something unexpected happened')
        return {'some': 'data'}
